#!/bin/bash
#SQOOP_HOME=/opt/cloudera/parcels/CDH-6.2.1-1.cdh6.2.1.p0.1425774/bin/sqoop
SQOOP_HOME=/usr/bin/sqoop
if [[ $1 == "" ]];then
   TD_DATE=`date -d '1 days ago' "+%Y-%m-%d"`
else
   TD_DATE=$1
fi

echo '========================================'
echo '==============开始增量导入==============='
echo '========================================'

# ========== 全量 ==========


# 4、employee员工表----------------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *,'${TD_DATE}' as dt from employee where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table employee \
--split-by id \
--m 100
wait

# 5、scrm_department部门表----------------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from scrm_department where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table scrm_department \
--split-by id \
--m 100
wait

# 6、itcast_school学校表----------------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *,'${TD_DATE}' as dt from itcast_school where \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table itcast_school \
--split-by id \
--m 100
wait

# 7、itcast_subject学科表----------------------------------------------------
/usr/bin/sqoop import \
--connect jdbc:mysql://106.75.33.59:3306/scrm \
--username itcast_edu_stu \
--password itcast_edu_stu \
--query "select *, '${TD_DATE}' as dt from itcast_subject where 1=1 and  \$CONDITIONS" \
--hcatalog-database notp_ods \
--hcatalog-table itcast_subject \
--split-by id \
--m 100

echo '========================================'
echo '=================success==============='
echo '========================================'